//
//  STCommodityListCollectionView.m
//  赛拓
//
//  Created by 王磊 on 8/9/16.
//  Copyright © 2016 立金所. All rights reserved.
//

#import "STCommodityListCollectionView.h"
#import "STCommodityBean.h"
static NSString *headerId = @"headerId";
@implementation STCommodityListCollectionView

- (void)commitInit {
    [super commitInit];
    
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
    
    header.automaticallyChangeAlpha = true;
    
    [header setValue:@(1) forKeyPath:@"lastUpdatedTimeLabel.hidden"];
    [header setTitle:@"下拉刷新" forState:MJRefreshStateIdle];
    [header setTitle:@"松开载入" forState:MJRefreshStatePulling];
    [header setTitle:@"正在载入..." forState:MJRefreshStateRefreshing];
    [header setTitle:@"正在载入..." forState:MJRefreshStateWillRefresh];
    [header setTitle:@"暂无更多数据" forState:MJRefreshStateNoMoreData];
    [header setValue:ST_BLACK_COLOR forKeyPath:@"stateLabel.textColor"];
    
    header.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    
    self.mj_header = header;
    
    [self.mj_header beginRefreshing];
    
    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    
    [footer setTitle:@"点击或上拉加载更多" forState:MJRefreshStateIdle];
    [footer setTitle:@"松开载入" forState:MJRefreshStatePulling];
    [footer setTitle:@"正在载入..." forState:MJRefreshStateRefreshing];
    [footer setTitle:@"正在载入..." forState:MJRefreshStateWillRefresh];
    [footer setValue:ST_BLACK_COLOR forKeyPath:@"stateLabel.textColor"];
    footer.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    [footer setTitle:@"暂无更多数据" forState:MJRefreshStateNoMoreData];
    
    self.mj_footer = footer;
    
    self.bounces = true;
}
- (void)loadNewData {
    
    [self.mDelegate loadNewData];
    
}
- (void)loadMoreData {
    
    //    [self.mDelegate loadMoreData];
}


- (void)onItemClick:(STItemClickType)itemType withData:(id)data forIndexPath:(NSIndexPath *)indexPath {
    
    [self.mDelegate onItemClick:itemType withData:data forIndexPath:indexPath];
    
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    STCommodityBean *goods = self.dataArray[indexPath.row];
    
    return [goods.type isEqualToString:@"2"] ? CGSizeMake(ST_SCREEN_WIDTH - 20, 100) : CGSizeMake(ST_SCREEN_WIDTH / 2 - 15 , 250);
    
}

- (void)updateData:(id)data {
    if (self.dataArray.count) {
        [self.dataArray removeAllObjects];
    }
    [self.dataArray addObjectsFromArray:data];
    
    [self reloadData];
}


@end
